<template>
  <div class="not-found">
    <van-empty
      image="error"
      description="页面不存在"
    >
      <template #bottom>
        <van-button
          round
          type="primary"
          @click="handleBack"
        >
          返回上一页
        </van-button>
        <van-button
          round
          plain
          type="primary"
          @click="handleHome"
          style="margin-left: 10px"
        >
          返回首页
        </van-button>
      </template>
    </van-empty>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

// 返回上一页
const handleBack = () => {
  const lastValidPath = sessionStorage.getItem('lastValidPath')
  if (lastValidPath) {
    router.replace(lastValidPath)
    sessionStorage.removeItem('lastValidPath')
  } else {
    router.back()
  }
}

// 返回首页
const handleHome = () => {
  const roleId = userStore.userInfo?.roleId
  let homePath = '/'
  
  if (roleId === 2) {
    homePath = '/doctor'
  } else if (roleId === 3) {
    homePath = '/home'
  }
  
  router.replace(homePath)
}
</script>

<style lang="scss" scoped>
.not-found {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f7f8fa;
  
  :deep(.van-empty) {
    padding: 32px 0;
  }
}
</style> 